package mytest.wd4;

import cn.hutool.core.lang.hash.Hash;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;

import javax.jws.soap.SOAPBinding;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Test_8 {
    public static void main(String[] args) {
        Map<String, Object> finalHashMap = new HashMap<>();
        Set<Map<String, Object>> extra = new HashSet<>();
        Map<String, Object> extraMap = new HashMap<>();

        HashMap<String, Object> hashMap1= new HashMap<>();
        hashMap1.put("key1", "value1");
        hashMap1.put("key2", "value2");
        HashMap<String, Object> hashMap2= new HashMap<>();
        hashMap2.put("key1", "value1");
        hashMap2.put("key2", "value2");
        extra.add(hashMap1);
        extra.add(hashMap2);
        extraMap.put("user_list", extra);
        finalHashMap.put("extra", extraMap);
        System.out.println("finalHashMap: " + finalHashMap);
        System.out.println("-------");
        Map extraMap2 = MapUtils.getMap(finalHashMap, "extra");
        System.out.println("extraMap2: " + extraMap2);
        System.out.println("-------");
        Set<Map<String, Object>> extraSet = (Set<Map<String, Object>>) extraMap2.get("user_list");
        Map<String, Object> zjlMap = new HashMap<>();
        zjlMap.put("zhangjiali", "111");
        extraSet.add(zjlMap);
        extraMap.put("user_list", extraSet);
        finalHashMap.put("extra", extraMap);
        System.out.println("extraSet: " + extraSet);
        System.out.println("--------");
        System.out.println(finalHashMap);
        System.out.println("--------");
        String json = new Gson().toJson(finalHashMap);
        System.out.println(json);
        System.out.println("-------");
        HashMap hashMap = new Gson().fromJson(json, HashMap.class);
        System.out.println(hashMap);

    }

    public static String joinColon(String... str) {
        return StringUtils.join(str, ":");
    }
}
